﻿@model WaiGaoQiaoWeb.Models.MenuMaintainVM
@{
    ViewBag.Title = "MenuMaintainIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    <script type="text/javascript" language="javascript">
        var mainheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 10;
        $(document).ready(function () {
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = mainheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetList")',
                dataType: 'json',
                colModel: [
                    { display: '编号', name: 'MenuId', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '名称', name: 'MenuName', width: 100, sortable: false, hide: false, align: 'left' },
			        { display: '类型', name: 'MenuType', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'MenuPrice', width: 100, sortable: false, hide: false, align: 'left' }
				],
                buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItemAdd_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItemEdit_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItemDel_onclick },
                            { separator: true }
                         ],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpOptions: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var instockgrid = $("#MenuList").flexigrid(option);

            function toolbarItemAdd_onclick(cmd) {
                OpenModelWindow('@Url.Action("AddMenu")',
                                   { width: 300, height: 250, caption: "添加菜单", onclose: refresh });
            }

            function toolbarItemEdit_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要修改的菜单!", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
                if (items.length > 1) {
                    showLoadingMsg("只能选择一个要修改的菜单!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                var id = items[0][0];
                OpenModelWindow('@Url.Action("EditMenu")?id=' + id,
                                   { width: 300, height: 250, caption: "修改菜单", onclose: refresh });
            }

            function toolbarItemDel_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的菜单!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除菜单吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteMenu")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });
                }
                refresh();
                showLoadingMsg("共有" + rowcount.toString() + "个菜单被删除!", { left: 400, top: 6 }, true, 3000);
            }

            $("#btnQueryList").click(function () {
                select();
            });
            function select() {
                var type = $("#ddlMenuType").val();
                var name = $("#txtMenuName").val();
                option.query = type + "," + name;
                option.newp = 0;
                $("#MenuList").flexOptions(option).flexReload();
            }
            function refresh() {
                $("#MenuList").flexOptions(option).flexReload();
            }
        });
    </script>
}
<div id="container">
    <div id="mainContent">
        <div id="title" class="title">
            菜单列表</div>
        <div id="findDiv">
            <table>
                <tr>
                    <td style="text-align: right; width: 60px;">
                        菜单类型:
                    </td>
                    <td>
                        @Html.DropDownList("ddlMenuType",
                                             ViewData["MenuType"] as IEnumerable<SelectListItem>,
                                      new { @style = "width:100px; height:22px; font-size:13px;" })
                    </td>
                    <td style="text-align: right; width: 60px;">
                        菜单名称:
                    </td>
                    <td>
                        @Html.TextBox("txtMenuName", "", new { @style = "width:100px;" })
                    </td>
                    <td>
                        <a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                    </td>
                </tr>
            </table>
        </div>
        <table id="MenuList" style="display: none;">
        </table>
    </div>
</div>
